package com.tedu.parkinglot.chargeRule.controller;

import com.tedu.parkinglot.base.response.JsonResult;
import com.tedu.parkinglot.chargeRule.pojo.dto.ChargeRuleQuery;
import com.tedu.parkinglot.chargeRule.pojo.dto.ChargeRuleSaveParam;
import com.tedu.parkinglot.chargeRule.pojo.vo.ChargeRuleVO;
import com.tedu.parkinglot.chargeRule.service.ChargeRuleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.List;

@Slf4j
@Api(tags = "收费规则管理")
@RestController
@RequestMapping("/v1/chargeRule/")
public class ChargeRuleController {

    @Autowired
    private ChargeRuleService chargeRuleService;

    @ApiOperation(value = "查询计费规则")
    @GetMapping("select")
    public JsonResult select(ChargeRuleQuery query){
        log.debug("查询计费规则：接收前端参数："+query);
        List<ChargeRuleVO> chargeRuleVOS= chargeRuleService.selectRules(query);
        log.debug("查询计费规则：返回结果："+chargeRuleVOS);
        return JsonResult.ok(chargeRuleVOS);
    }

    @ApiOperation(value = "保存计费规则")
    @PostMapping("save")
    public JsonResult save(ChargeRuleSaveParam param){
        log.debug("保存计费规则：接收前端参数："+param);
        chargeRuleService.saveRule(param);
        return JsonResult.ok();
    }
    @ApiOperation(value = "删除计费规则")
    @PostMapping("delete/{id}")
    public JsonResult delete(@PathVariable Long id){
        log.debug("删除计费规则：接收前端参数："+id);
        chargeRuleService.deleteRule(id);
        return JsonResult.ok();
    }
}
